from odoo import models, api


class TransferIssueReport(models.AbstractModel):
    _name = "report.sb_workflow_purchase.purchase_outsource_label"
    _description = '采购外包'

    @api.model
    def _get_report_values(self, docids, data=None):
        purchase_ids = self.env['purchase.order'].search([('id', 'in', docids)])
        data = []
        for purchase in purchase_ids:
            order_line = []
            for line in purchase.order_line:
                order_line.append({
                    'id': line.id,
                    'work': line.s_production_id.name,
                    'product_id': line.s_subcontracting_product_id.name,  # 型号
                    's_area': line.s_area,  # 平米
                    's_specs': line.s_specs,  # 规格 pnll
                    'product_uom': 'PNL',  # 计量单位
                    'product_qty': line.product_qty,  # 数量
                    'remark': line.name  # 备注
                })
            dtl = {
                'id': purchase.id,
                'name': purchase.name,
                'date_approve': purchase.date_approve,
                'type': purchase.order_line[0].product_id.name if purchase.order_line else '',
                'partner_id': purchase.partner_id.name,
                'order_line': order_line,
            }
            data.append(dtl)
        return {
            'report_title': 'Purchase Order(PDF)',
            'doc_model': 'purchase.order',
            'docs': docids,
            'data': data,
        }
